package com.chiwen.common.utils;

import cn.hutool.json.ObjectMapper;
import com.alibaba.fastjson2.JSONArray;
import com.chiwen.common.constant.CacheConstants;
import com.chiwen.common.core.domain.entity.SysDictData;
import com.chiwen.common.core.domain.entity.SysPayway;
import com.chiwen.common.core.redis.RedisCache;
import com.chiwen.common.utils.spring.SpringUtils;

import java.io.IOException;
import java.util.Collection;
import java.util.List;

/**
 * 字典工具类
 * 
 * @author Dipper
 */
public class PayWayUtils
{
    /**
     * 分隔符
     */
    public static final String SEPARATOR = ",";

    /**
     * 设置字典缓存
     * 
     * @param key 参数键
     * @param sysPayway 字典数据列表
     */
    public static void setDictCache(String key, SysPayway sysPayway)
    {
        SpringUtils.getBean(RedisCache.class).setCacheObject(getCacheKey(key), sysPayway);
    }

    /**
     * 获取字典缓存
     * 
     * @param key 参数键
     * @return dictDatas 字典数据列表
     */
    public static SysPayway getDictCache(String key)
    {
        SysPayway arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
        if (StringUtils.isNotNull(arrayCache))
        {
            return arrayCache ;
        }
        return null;
    }









    /**
     * 删除指定字典缓存
     * 
     * @param key 字典键
     */
    public static void removeDictCache(String key)
    {
        SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
    }

    /**
     * 清空字典缓存
     */
    public static void clearDictCache()
    {
        Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_PAY_WAY + "*");
        SpringUtils.getBean(RedisCache.class).deleteObject(keys);
    }

    /**
     * 设置cache key
     * 
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getCacheKey(String configKey)
    {
        return CacheConstants.SYS_PAY_WAY + configKey;
    }
}
